﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ScarletTest.Models;

namespace ScarletTest.Controllers
{
    public class BaseTestController : Controller
    {
        private ScarletContext db = new ScarletContext();

        //
        // GET: /BaseTest/

        public string Hello()
        {
            return "Hello World";
        }

        public ActionResult Index()
        {
            return View(db.TestModels.ToList());
        }

        //
        // GET: /BaseTest/Details/5

        public ActionResult Details(int id = 0)
        {
            TestModel testmodel = db.TestModels.Find(id);
            if (testmodel == null)
            {
                return HttpNotFound();
            }
            return View(testmodel);
        }

        //
        // GET: /BaseTest/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /BaseTest/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(TestModel testmodel)
        {
            if (ModelState.IsValid)
            {
                db.TestModels.Add(testmodel);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(testmodel);
        }

        //
        // GET: /BaseTest/Edit/5

        public ActionResult Edit(int id = 0)
        {
            TestModel testmodel = db.TestModels.Find(id);
            if (testmodel == null)
            {
                return HttpNotFound();
            }
            return View(testmodel);
        }

        //
        // POST: /BaseTest/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(TestModel testmodel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(testmodel).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(testmodel);
        }

        //
        // GET: /BaseTest/Delete/5

        public ActionResult Delete(int id = 0)
        {
            TestModel testmodel = db.TestModels.Find(id);
            if (testmodel == null)
            {
                return HttpNotFound();
            }
            return View(testmodel);
        }

        //
        // POST: /BaseTest/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            TestModel testmodel = db.TestModels.Find(id);
            db.TestModels.Remove(testmodel);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}